<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/2 0002
 * Time: 上午 10:14
 */

namespace app\home\controller;
use app\home\model\WechatUser;
use think\Db;

class Index extends Base {

    public function index(){
        $userId = session('userId');
        $this->anonymous();
        $info = WechatUser::where(['userid' => $userId])->field('name')->find();
        $this->assign('info',$info);
        // 村规民约
        $list1 = Db::name('regulation')->where(['recommend' => 1,'status' => ['egt',0]])->order('id','desc')->select();
        foreach($list1 as $key => $value){
            $list1[$key]['class'] = 1;
        }

        if($userId !== 'visitor'){
            // 党务公开
            $list2 = Db::name('party')->where(['recommend' => 1,'status' => ['egt',0]])->order('id','desc')->select();
            foreach($list2 as $value){
                $value['class'] = 2;
                array_push($list1,$value);
            }
        }

        // 美丽乡村
        $list3 = Db::name('country')->where(['recommend' => 1,'status' => ['egt',0]])->order('id','desc')->select();
        foreach($list3 as $value){
            $value['class'] = 3;
            array_push($list1,$value);
        }
        // 排序 只要 前10条
        array_multisort(array_column($list1,'create_time'),SORT_DESC,$list1);
        foreach ($list1 as $key => $value){
            if ($key > 9){
                unset($list1[$key]);
            }
        }
        $this->assign('msg',$list1);
        return $this->fetch();
    }
}